home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / xpkmaster / xbuf.c < prev    next >
C/C++ Source or Header  |  1998-08-27  |  2KB  |  67 lines

  1. #ifndef XPKMASTER_XBUF_C
  2. #define XPKMASTER_XBUF_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        xbuf.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: xbuf.c 1.2 (09.01.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Xpk buffer handling
  12.  
  13.  1.0   09.10.96 : first real version
  14.  1.1   31.02.97 : now free's password buffer
  15.  1.2   09.09.98 : added XPK_ALLINONE
  16. */
  17.  
  18. #include <proto/exec.h>
  19. #include <exec/memory.h>
  20. #include <exec/libraries.h>
  21. #include <dos/dos.h>
  22. #include "xpkmaster.h"
  23.  
  24. /************************* alloc and init xbuf ***************************/
  25.  
  26. XPK_ALLINONE struct XpkBuffer *initxbuf(void)
  27. {
  28.   struct XpkBuffer *xbuf;
  29.  
  30.   if(!(xbuf = (struct XpkBuffer *) AllocMem(sizeof(struct XpkBuffer),
  31.   MEMF_CLEAR)))
  32.     return 0;
  33.   /* Save the original task priority in case we change it during an
  34.      operation */
  35.  
  36.   xbuf->xb_Priority = FindTask(0L)->tc_Node.ln_Pri;
  37.  
  38.   xbuf->xb_InLen = 0xFFFFFFFF;
  39.  
  40.   return xbuf;
  41. }
  42.  
  43. /***************************** free bufs *******************************/
  44. XPK_ALLINONE LONG freebufs(struct XpkBuffer *xbuf)
  45. {                /* Free an XpkBuffer */
  46.   LONG error = xbuf->xb_Result;
  47.  
  48.   if(xbuf->xb_xfd)
  49.   {
  50.     struct xfdMasterBase *xfdMasterBase = (struct xfdMasterBase *) xbuf->xb_SubBase;
  51.     xfdFreeObject(xbuf->xb_xfd);
  52.   }
  53.  
  54.   closesub(xbuf);            /* Free any open sub-library */
  55.  
  56.   if(xbuf->xb_Flags & XMF_OWNTASKPRI)
  57.     SetTaskPri(FindTask (NULL), xbuf->xb_Priority);
  58.   if(xbuf->xb_Flags & XMF_OWNPASSWORD)
  59.     FreeMem(xbuf->xb_Password, xbuf->xb_PasswordSize);
  60.  
  61.   FreeMem(xbuf, sizeof(struct XpkBuffer));
  62.                 /* Finally, free the handle itself */
  63.   return error;
  64. }
  65.  
  66. #endif /* XPKMASTER_XBUF_C */
  67.